package com.takanafu.haru.code{
	import com.takanafu.haru.code.CodeBase;
	
	public class CodeIf extends CodeBase{
		private var cond:CodeBase;
		private var then_body:CodeBase;
		private var else_body:CodeBase;
		
		public function CodeIf(code:CodeBase,left:CodeBase,right:CodeBase){
			this.cond = code;
			this.then_body = left;
			this.else_body = right;
		}
		override public function run():CodeBase{
			var c:CodeBase;
			var p:CodeBase = this.cond.run();
			
			if(p != CodeBoolean.False){
				c = this.then_body;
			}else{
				c = this.else_body;
			}
			if(c != null){
				c.thread = this.thread;
				c = c.run();
			}
			return c;
		}
	}
}